﻿using Manon.Admin.Web.ApplicationCore.Dtos.News;
using Manon.Admin.Web.ApplicationCore.Interfaces;
using Manon.Core.IOC;
using Manon.Core.Commons;
using Manon.Repository.Collections;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Manon.Admin.Web.Controllers
{
    public class NewsController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Edit()
        {
            return View();
        }


        [Authorize]
        [HttpPost]
        public async Task<IPagedList<NewsOutput>> GetNewsPageList([FromBody] GetNewsPagedListInput Input)
        {

            var newsCategory = Resolver.GetService<INewsService>();
            var result = await newsCategory.GetNewsPagedList(Input);

            return result;
        }

        [Authorize]
        [HttpPost]
        public async Task<Result> SaveNews([FromBody] NewsInput Input)
        {
            var newsCategory = Resolver.GetService<INewsService>();
            var result = await newsCategory.SaveNews(Input);
            return result;
        }
        [Authorize]
        [HttpGet]
        public async Task<NewsOutput> GetNews(int Id)
        {

            var newsCategory = Resolver.GetService<INewsService>();
            var result = await newsCategory.GetNews(Id);
            return result;
        }
        [Authorize]
        [HttpPost]
        public async Task<Result> SetNewsEnabled(int Id, bool Enabled)
        {

            var newsCategory = Resolver.GetService<INewsService>();
            var result = await newsCategory.SetNewsEnabled(Id, Enabled);
            return result;
        }
    }
}
